
#import "GameManager.h"

float W=320;
float H=480;

@implementation GameManager

#pragma mark ============================= Init Methods ================================

+ (GameManager*) getInstance  {
    
    static GameManager* gameManager;
		
	if (!gameManager) {
        gameManager = [[GameManager alloc] init];
		[gameManager preloader];            
	}
	    
    return gameManager;
}

- (void) preloader {       
    [self setOGLProjection];
    
    state = LOAD_GAME;
}

- (void) loadGame {     
}

#pragma mark ============================= Game Handler ===============================

- (void) touchBegan: (CGPoint) p {      
    NSLog(@"Touch: %f %f", p.x, p.y);
}

- (void) touchMoved: (CGPoint) p {
    [self touchBegan: p];      
}

- (void) touchEnded {
}

- (void) drawStatesWithFrame: (CGRect) frame { 
    W = frame.size.width;
    H = frame.size.height; 
    switch (state) {
        case LOAD_GAME: 
            [self loadGame];            
            state = PLAY_GAME;
            break;  
        case PLAY_GAME:
            [self playGame];
            break;           
        default: NSLog(@"ERROR: Unknown state: %i", state);
            break;
    }    
}	 

- (void) playGame {
    timer++;     
//    [self drawCube_noTexture];
//    [self drawCube];
    
//    [self drawYuan];
    [self drawMyCube];
}

#pragma mark ============================= OGL Methods ===============================

- (void) setOGLProjection {    
    glLoadIdentity();
    
    //Set View
    glMatrixMode(GL_PROJECTION);     
    zNear = 0.1; 
    zFar = 2500;    
    fieldOfViewAngle = 45;
    float top = zNear * tan(M_PI * fieldOfViewAngle / W);
    float bottom = -top;
    float left = bottom * W / H; 
    float right = top * W / H;    
    glFrustumf(left, right, bottom, top, zNear, zFar); 
    
    glMatrixMode(GL_MODELVIEW);
    glEnableClientState(GL_VERTEX_ARRAY);    
    glEnable(GL_DEPTH_TEST); 
    glDepthFunc(GL_LESS);
    
    [self setLight]; 
} 

- (void) setLight {    
    glEnable(GL_LIGHTING);     
    glEnable(GL_COLOR_MATERIAL); 
    
    glEnable(GL_LIGHT0); 
    GLfloat color0[ ] = {1, 1, 1, 1};     
    glLightfv(GL_LIGHT0, GL_DIFFUSE, color0);
//    光源位置
//    GLfloat light_position0[ ] = {0, 1, 0, 0};
    GLfloat light_position0[ ] = {-0.5, 1, 0.5, 0};
    glLightfv(GL_LIGHT0, GL_POSITION, light_position0); 
}

- (void) drawCube {    
      
    GLfloat vertices[ ] = {
        -1, -1,  1, 
         1, -1,  1,
        -1,  1,  1,
         1,  1,  1,
        
        -1, -1, -1, 
        -1,  1, -1,
         1, -1, -1,
         1,  1, -1,
        
        -1,  1,  1, 
         1,  1,  1,
        -1,  1, -1,
         1,  1, -1,
        
        -1, -1,  1, 
        -1, -1, -1,
         1, -1,  1,
         1, -1, -1,
        
        -1, -1,  1, 
        -1,  1,  1,
        -1, -1, -1,
        -1,  1, -1,
        
         1, -1, -1, 
         1,  1, -1,
         1, -1,  1,
         1,  1,  1  
    };          
    
    GLfloat textureCoords[ ] = {                
        1, 0, 
        0, 0, 
        1, 1, 
        0, 1,    
        
        1, 0, 
        0, 0, 
        1, 1, 
        0, 1,   
        
        1, 0, 
        0, 0, 
        1, 1, 
        0, 1,   
        
        1, 0, 
        0, 0, 
        1, 1, 
        0, 1,   
        
        1, 0, 
        0, 0, 
        1, 1,
        0, 1, 
        
        1, 0, 
        0, 0, 
        1, 1, 
        0, 1
    };
    
    Tex *tex = [[GameManager getInstance] getTex: @"textur.png" isImage: YES];
    GLuint textureID = [tex getTextureID]; 
    
    int verticesLength = sizeof(vertices) / sizeof(GLfloat);
    
    /* 
    for (int i = 0; i < verticesLength; i++) {
        vertices[i] += ([self getRndBetween: -1 and: 1] * 0.02);
    }
    */
    
    glEnable(GL_CULL_FACE); 
    glCullFace(GL_BACK);    
    
    glEnable(GL_TEXTURE_2D); 
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glBindTexture(GL_TEXTURE_2D, textureID);     
    glTexCoordPointer(2, GL_FLOAT, 0, textureCoords);      
    
    glColor4f(1, 1, 1, 1); 
    
    //Matrix-Operations
    glPushMatrix();  
    glTranslatef(0, 0, -5);
    static int angle = 0; angle += 2;
    glRotatef(angle, 1, 1, 1);    
    glDrawArrays(GL_TRIANGLE_STRIP, 0, verticesLength/3);     
    glPopMatrix();
    
    //Cleanup
    glDisable(GL_TEXTURE_2D);     
    glDisable(GL_CULL_FACE);              
}

- (void) drawCube_noTexture {
    
    GLfloat vertices[ ] = {
       -1, -1,  1, 
        1, -1,  1,
       -1,  1,  1,
        1,  1,  1,
        
       -1, -1, -1, 
       -1,  1, -1,
        1, -1, -1,
        1,  1, -1,
        
       -1,  1,  1, 
        1,  1,  1,
       -1,  1, -1,
        1,  1, -1,
        
       -1, -1,  1, 
       -1, -1, -1,
        1, -1,  1,
        1, -1, -1,
        
       -1, -1,  1,
       -1,  1,  1,
       -1, -1, -1,
       -1,  1, -1,
        
        1, -1, -1, 
        1,  1, -1,
        1, -1,  1,
        1,  1,  1  
    };    
    
    GLfloat normals[ ] = {
        0,  0,  1, 
        0,  0,  1,
        0,  0,  1,
        0,  0,  1,
        
        0,  0, -1, 
        0,  0, -1,
        0,  0, -1,
        0,  0, -1,
        
        0,  1,  0, 
        0,  1,  0,
        0,  1,  0,
        0,  1,  0,
        
        0, -1,  0, 
        0, -1,  0,
        0, -1,  0,
        0, -1,  0,
        
       -1,  0,  0, 
       -1,  0,  0,
       -1,  0,  0,
       -1,  0,  0,
        
        1,  0,  0, 
        1,  0,  0,
        1,  0,  0,
        1,  0,  0   
    };
    
    int verticesLength = sizeof(vertices) / sizeof(GLfloat);
    
    glEnableClientState(GL_NORMAL_ARRAY);             
    glEnable(GL_NORMALIZE);     
    
    glEnable(GL_CULL_FACE); 
    glCullFace(GL_BACK);    
    
    glVertexPointer(3, GL_FLOAT, 0, vertices);      
    glNormalPointer(GL_FLOAT, 0, normals);
    
    glColor4f(0, 0, 1, 1); 
    
    //Matrix-Operations
    glPushMatrix();  
    glTranslatef(0, 0, -7);
    static int angle = 0; angle += 2;
    glRotatef(angle, 1, 1, 0);    
    glDrawArrays(GL_TRIANGLE_STRIP, 0, verticesLength/3);      
    glPopMatrix();
    
    //Cleanup 
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisable(GL_NORMALIZE);     
    glDisable(GL_CULL_FACE);  
}

- (void) drawYuan
{
//    顶点
    GLfloat vertices[ ] ={
        1.033109, -6.834531, -0.334506, 0.879354, -6.834531, -0.636268, 0.639874, -6.834531, -0.875748, 0.338112, -6.834531, -1.029504, 0.003606, -6.834531, -1.082484, -0.330900, -6.834531, -1.029503, -0.632662, -6.834531, -0.875748, -0.872142, -6.834531, -0.636268, -1.025898, -6.834531, -0.334506, -1.078878, -6.834531, 0.000000, -1.025898, -6.834531, 0.334506, -0.872142, -6.834531, 0.636268, -0.632662, -6.834531, 0.875748, -0.330900, -6.834531, 1.029503, 0.003606, -6.834531, 1.082484, 0.338111, -6.834531, 1.029503, 0.639873, -6.834531, 0.875748, 0.879353, -6.834531, 0.636268, 1.033109, -6.834531, 0.334506, 1.086089, -6.834531, 0.000000, 2.037263, -6.581049, -0.660775, 1.733538, -6.581049, -1.256869, 1.260475, -6.581049, -1.729932, 0.664381, -6.581049, -2.033657, 0.003606, -6.581049, -2.138314, -0.657170, -6.581049, -2.033657, -1.253263, -6.581049, -1.729932, -1.726326, -6.581049, -1.256869, -2.030051, -6.581049, -0.660775, -2.134707, -6.581049, 0.000000, -2.030051, -6.581049, 0.660775, -1.726326, -6.581049, 1.256869, -1.253263, -6.581049, 1.729931, -0.657169, -6.581049, 2.033656, 0.003606, -6.581049, 2.138313, 0.664381, -6.581049, 2.033656, 1.260474, -6.581049, 1.729931, 1.733537, -6.581049, 1.256869, 2.037262, -6.581049, 0.660775, 2.141918, -6.581049, 0.000000, 2.991341, -6.165520, -0.970774, 2.545126, -6.165520, -1.846522, 1.850128, -6.165520, -2.541520, 0.974380, -6.165520, -2.987736, 0.003606, -6.165520, -3.141491, -0.967168, -6.165520, -2.987735, -1.842916, -6.165520, -2.541519, -2.537913, -6.165520, -1.846522, -2.984129, -6.165520, -0.970774, -3.137884, -6.165520, 0.000000, -2.984129, -6.165520, 0.970774, -2.537913, -6.165520, 1.846521, -1.842916, -6.165520, 2.541519, -0.967168, -6.165520, 2.987734, 0.003606, -6.165520, 3.141490, 0.974379, -6.165520, 2.987734, 1.850127, -6.165520, 2.541518, 2.545124, -6.165520, 1.846521, 2.991339, -6.165520, 0.970774, 3.145095, -6.165520, 0.000000, 3.871851, -5.598175, -1.256869, 3.294132, -5.598175, -2.390707, 2.394313, -5.598175, -3.290526, 1.260475, -5.598175, -3.868245, 0.003606, -5.598175, -4.067314, -1.253263, -5.598175, -3.868245, -2.387101, -5.598175, -3.290526, -3.286920, -5.598175, -2.390707, -3.864639, -5.598175, -1.256869, -4.063707, -5.598175, 0.000000, -3.864639, -5.598175, 1.256869, -3.286920, -5.598175, 2.390706, -2.387101, -5.598175, 3.290525, -1.253263, -5.598175, 3.868244, 0.003606, -5.598175, 4.067312, 1.260474, -5.598175, 3.868244, 2.394311, -5.598175, 3.290525, 3.294130, -5.598175, 2.390706, 3.871849, -5.598175, 1.256868, 4.070917, -5.598175, 0.000000, 4.657113, -4.892984, -1.512016, 3.962116, -4.892984, -2.876025, 2.879631, -4.892984, -3.958509, 1.515622, -4.892984, -4.653507, 0.003606, -4.892984, -4.892986, -1.508410, -4.892984, -4.653506, -2.872419, -4.892984, -3.958509, -3.954903, -4.892984, -2.876025, -4.649900, -4.892984, -1.512015, -4.889379, -4.892984, 0.000000, -4.649900, -4.892984, 1.512015, -3.954902, -4.892984, 2.876024, -2.872419, -4.892984, 3.958508, -1.508410, -4.892984, 4.653505, 0.003605, -4.892984, 4.892984, 1.515621, -4.892984, 4.653505, 2.879629, -4.892984, 3.958508, 3.962113, -4.892984, 2.876024, 4.657110, -4.892984, 1.512015, 4.896590, -4.892984, 0.000000, 5.327790, -4.067312, -1.729932, 4.532627, -4.067312, -3.290526, 3.294132, -4.067312, -4.529021, 1.733538, -4.067312, -5.324183, 0.003606, -4.067312, -5.598177, -1.726326, -4.067312, -5.324183, -3.286920, -4.067312, -4.529020, -4.525414, -4.067312, -3.290525, -5.320576, -4.067312, -1.729931, -5.594570, -4.067312, 0.000000, -5.320576, -4.067312, 1.729931, -4.525414, -4.067312, 3.290525, -3.286919, -4.067312, 4.529019, -1.726326, -4.067312, 5.324181, 0.003605, -4.067312, 5.598175, 1.733537, -4.067312, 5.324181, 3.294130, -4.067312, 4.529019, 4.532624, -4.067312, 3.290525, 5.327786, -4.067312, 1.729931, 5.601780, -4.067312, 0.000000, 5.867367, -3.141489, -1.905252, 4.991619, -3.141489, -3.624004, 3.627609, -3.141489, -4.988013, 1.908857, -3.141489, -5.863761, 0.003606, -3.141489, -6.165523, -1.901646, -3.141489, -5.863760, -3.620397, -3.141489, -4.988012, -4.984406, -3.141489, -3.624003, -5.860154, -3.141489, -1.905251, -6.161916, -3.141489, 0.000000, -5.860154, -3.141489, 1.905251, -4.984406, -3.141489, 3.624002, -3.620397, -3.141489, 4.988011, -1.901645, -3.141489, 5.863759, 0.003605, -3.141489, 6.165521, 1.908856, -3.141489, 5.863758, 3.627607, -3.141489, 4.988011, 4.991616, -3.141489, 3.624002, 5.867363, -3.141489, 1.905250, 6.169125, -3.141489, 0.000000, 6.262560, -2.138312, -2.033657, 5.327790, -2.138312, -3.868246, 3.871852, -2.138312, -5.324184, 2.037263, -2.138312, -6.258953, 0.003606, -2.138312, -6.581053, -2.030051, -2.138312, -6.258953, -3.864640, -2.138312, -5.324183, -5.320577, -2.138312, -3.868245, -6.255346, -2.138312, -2.033657, -6.577445, -2.138312, 0.000000, -6.255346, -2.138312, 2.033657, -5.320576, -2.138312, 3.868245, -3.864639, -2.138312, 5.324182, -2.030051, -2.138312, 6.258951, 0.003605, -2.138312, 6.581050, 2.037262, -2.138312, 6.258951, 3.871849, -2.138312, 5.324181, 5.327787, -2.138312, 3.868244, 6.262556, -2.138312, 2.033656, 6.584655, -2.138312, 0.000000, 6.503635, -1.082483, -2.111988, 5.532861, -1.082483, -4.017239, 4.020845, -1.082483, -5.529255, 2.115593, -1.082483, -6.500029, 0.003606, -1.082483, -6.834535, -2.108382, -1.082483, -6.500029, -4.013633, -1.082483, -5.529254, -5.525648, -1.082483, -4.017238, -6.496422, -1.082483, -2.111987, -6.830927, -1.082483, 0.000000, -6.496422, -1.082483, 2.111987, -5.525648, -1.082483, 4.017238, -4.013632, -1.082483, 5.529253, -2.108381, -1.082483, 6.500027, 0.003605, -1.082483, 6.834532, 2.115592, -1.082483, 6.500026, 4.020842, -1.082483, 5.529253, 5.532858, -1.082483, 4.017237, 6.503631, -1.082483, 2.111986, 6.838137, -1.082483, 0.000000, 6.584659, 0.000000, -2.138314, 5.601784, 0.000000, -4.067315, 4.070920, 0.000000, -5.598178, 2.141919, 0.000000, -6.581052, 0.003606, 0.000000, -6.919728, -2.134708, 0.000000, -6.581052, -4.063708, 0.000000, -5.598177, -5.594571, 0.000000, -4.067313, -6.577445, 0.000000, -2.138313, -6.916120, 0.000000, 0.000000, -6.577445, 0.000000, 2.138313, -5.594570, 0.000000, 4.067313, -4.063707, 0.000000, 5.598176, -2.134707, 0.000000, 6.581050, 0.003605, 0.000000, 6.919725, 2.141918, 0.000000, 6.581049, 4.070917, 0.000000, 5.598175, 5.601780, 0.000000, 4.067312, 6.584655, 0.000000, 2.138313, 6.923330, 0.000000, 0.000000, 6.503635, 1.082483, -2.111988, 5.532861, 1.082483, -4.017239, 4.020845, 1.082483, -5.529255, 2.115593, 1.082483, -6.500029, 0.003606, 1.082483, -6.834535, -2.108382, 1.082483, -6.500029, -4.013633, 1.082483, -5.529254, -5.525648, 1.082483, -4.017238, -6.496422, 1.082483, -2.111987, -6.830927, 1.082483, 0.000000, -6.496422, 1.082483, 2.111987, -5.525648, 1.082483, 4.017238, -4.013632, 1.082483, 5.529253, -2.108381, 1.082483, 6.500027, 0.003605, 1.082483, 6.834532, 2.115592, 1.082483, 6.500026, 4.020842, 1.082483, 5.529253, 5.532858, 1.082483, 4.017237, 6.503631, 1.082483, 2.111986, 6.838137, 1.082483, 0.000000, 6.262560, 2.138312, -2.033657, 5.327790, 2.138312, -3.868246, 3.871852, 2.138312, -5.324184, 2.037263, 2.138312, -6.258953, 0.003606, 2.138312, -6.581053, -2.030051, 2.138312, -6.258953, -3.864640, 2.138312, -5.324183, -5.320577, 2.138312, -3.868245, -6.255346, 2.138312, -2.033657, -6.577445, 2.138312, 0.000000, -6.255346, 2.138312, 2.033657, -5.320576, 2.138312, 3.868245, -3.864639, 2.138312, 5.324182, -2.030051, 2.138312, 6.258951, 0.003605, 2.138312, 6.581050, 2.037262, 2.138312, 6.258951, 3.871849, 2.138312, 5.324181, 5.327787, 2.138312, 3.868244, 6.262556, 2.138312, 2.033656, 6.584655, 2.138312, 0.000000, 5.867367, 3.141489, -1.905252, 4.991619, 3.141489, -3.624004, 3.627609, 3.141489, -4.988013, 1.908857, 3.141489, -5.863761, 0.003606, 3.141489, -6.165523, -1.901646, 3.141489, -5.863760, -3.620397, 3.141489, -4.988012, -4.984406, 3.141489, -3.624003, -5.860154, 3.141489, -1.905251, -6.161916, 3.141489, 0.000000, -5.860154, 3.141489, 1.905251, -4.984406, 3.141489, 3.624002, -3.620397, 3.141489, 4.988011, -1.901645, 3.141489, 5.863759, 0.003605, 3.141489, 6.165521, 1.908856, 3.141489, 5.863758, 3.627607, 3.141489, 4.988011, 4.991616, 3.141489, 3.624002, 5.867363, 3.141489, 1.905250, 6.169125, 3.141489, 0.000000, 5.327790, 4.067312, -1.729932, 4.532627, 4.067312, -3.290526, 3.294132, 4.067312, -4.529021, 1.733538, 4.067312, -5.324183, 0.003606, 4.067312, -5.598177, -1.726326, 4.067312, -5.324183, -3.286920, 4.067312, -4.529020, -4.525414, 4.067312, -3.290525, -5.320576, 4.067312, -1.729931, -5.594570, 4.067312, 0.000000, -5.320576, 4.067312, 1.729931, -4.525414, 4.067312, 3.290525, -3.286919, 4.067312, 4.529019, -1.726326, 4.067312, 5.324181, 0.003605, 4.067312, 5.598175, 1.733537, 4.067312, 5.324181, 3.294130, 4.067312, 4.529019, 4.532624, 4.067312, 3.290525, 5.327786, 4.067312, 1.729931, 5.601780, 4.067312, 0.000000, 4.657113, 4.892984, -1.512016, 3.962116, 4.892984, -2.876025, 2.879631, 4.892984, -3.958509, 1.515622, 4.892984, -4.653507, 0.003606, 4.892984, -4.892986, -1.508410, 4.892984, -4.653506, -2.872419, 4.892984, -3.958509, -3.954903, 4.892984, -2.876025, -4.649900, 4.892984, -1.512015, -4.889379, 4.892984, 0.000000, -4.649900, 4.892984, 1.512015, -3.954902, 4.892984, 2.876024, -2.872419, 4.892984, 3.958508, -1.508410, 4.892984, 4.653505, 0.003605, 4.892984, 4.892984, 1.515621, 4.892984, 4.653505, 2.879629, 4.892984, 3.958508, 3.962113, 4.892984, 2.876024, 4.657110, 4.892984, 1.512015, 4.896590, 4.892984, 0.000000, 3.871851, 5.598175, -1.256869, 3.294132, 5.598175, -2.390707, 2.394313, 5.598175, -3.290526, 1.260475, 5.598175, -3.868245, 0.003606, 5.598175, -4.067314, -1.253263, 5.598175, -3.868245, -2.387101, 5.598175, -3.290526, -3.286920, 5.598175, -2.390707, -3.864639, 5.598175, -1.256869, -4.063707, 5.598175, 0.000000, -3.864639, 5.598175, 1.256869, -3.286920, 5.598175, 2.390706, -2.387101, 5.598175, 3.290525, -1.253263, 5.598175, 3.868244, 0.003606, 5.598175, 4.067312, 1.260474, 5.598175, 3.868244, 2.394311, 5.598175, 3.290525, 3.294130, 5.598175, 2.390706, 3.871849, 5.598175, 1.256868, 4.070917, 5.598175, 0.000000, 2.991341, 6.165520, -0.970774, 2.545126, 6.165520, -1.846522, 1.850128, 6.165520, -2.541520, 0.974380, 6.165520, -2.987736, 0.003606, 6.165520, -3.141491, -0.967168, 6.165520, -2.987735, -1.842916, 6.165520, -2.541519, -2.537913, 6.165520, -1.846522, -2.984129, 6.165520, -0.970774, -3.137884, 6.165520, 0.000000, -2.984129, 6.165520, 0.970774, -2.537913, 6.165520, 1.846521, -1.842916, 6.165520, 2.541519, -0.967168, 6.165520, 2.987734, 0.003606, 6.165520, 3.141490, 0.974379, 6.165520, 2.987734, 1.850127, 6.165520, 2.541518, 2.545124, 6.165520, 1.846521, 2.991339, 6.165520, 0.970774, 3.145095, 6.165520, 0.000000, 2.037263, 6.581049, -0.660775, 1.733538, 6.581049, -1.256869, 1.260475, 6.581049, -1.729932, 0.664381, 6.581049, -2.033657, 0.003606, 6.581049, -2.138314, -0.657170, 6.581049, -2.033657, -1.253263, 6.581049, -1.729932, -1.726326, 6.581049, -1.256869, -2.030051, 6.581049, -0.660775, -2.134707, 6.581049, 0.000000, -2.030051, 6.581049, 0.660775, -1.726326, 6.581049, 1.256869, -1.253263, 6.581049, 1.729931, -0.657169, 6.581049, 2.033656, 0.003606, 6.581049, 2.138313, 0.664381, 6.581049, 2.033656, 1.260474, 6.581049, 1.729931, 1.733537, 6.581049, 1.256869, 2.037262, 6.581049, 0.660775, 2.141918, 6.581049, 0.000000, 1.033109, 6.834531, -0.334506, 0.879354, 6.834531, -0.636268, 0.639874, 6.834531, -0.875748, 0.338112, 6.834531, -1.029504, 0.003606, 6.834531, -1.082484, -0.330900, 6.834531, -1.029503, -0.632662, 6.834531, -0.875748, -0.872142, 6.834531, -0.636268, -1.025898, 6.834531, -0.334506, -1.078878, 6.834531, 0.000000, -1.025898, 6.834531, 0.334506, -0.872142, 6.834531, 0.636268, -0.632662, 6.834531, 0.875748, -0.330900, 6.834531, 1.029503, 0.003606, 6.834531, 1.082484, 0.338111, 6.834531, 1.029503, 0.639873, 6.834531, 0.875748, 0.879353, 6.834531, 0.636268, 1.033109, 6.834531, 0.334506, 1.086089, 6.834531, 0.000000, 0.003606, -6.919724, 0.000000, 0.003606, 6.919724, 0.000000
    };
//    纹理坐标
    CGFloat textureCoordinates[]={
        0.000000, 0.050000, 0.050000, 0.050000, 0.100000, 0.050000, 0.150000, 0.050000, 0.200000, 0.050000, 0.250000, 0.050000, 0.300000, 0.050000, 0.350000, 0.050000, 0.400000, 0.050000, 0.450000, 0.050000, 0.500000, 0.050000, 0.550000, 0.050000, 0.600000, 0.050000, 0.650000, 0.050000, 0.700000, 0.050000, 0.750000, 0.050000, 0.800000, 0.050000, 0.850000, 0.050000, 0.900000, 0.050000, 0.950000, 0.050000, 1.000000, 0.050000, 0.000000, 0.100000, 0.050000, 0.100000, 0.100000, 0.100000, 0.150000, 0.100000, 0.200000, 0.100000, 0.250000, 0.100000, 0.300000, 0.100000, 0.350000, 0.100000, 0.400000, 0.100000, 0.450000, 0.100000, 0.500000, 0.100000, 0.550000, 0.100000, 0.600000, 0.100000, 0.650000, 0.100000, 0.700000, 0.100000, 0.750000, 0.100000, 0.800000, 0.100000, 0.850000, 0.100000, 0.900000, 0.100000, 0.950000, 0.100000, 1.000000, 0.100000, 0.000000, 0.150000, 0.050000, 0.150000, 0.100000, 0.150000, 0.150000, 0.150000, 0.200000, 0.150000, 0.250000, 0.150000, 0.300000, 0.150000, 0.350000, 0.150000, 0.400000, 0.150000, 0.450000, 0.150000, 0.500000, 0.150000, 0.550000, 0.150000, 0.600000, 0.150000, 0.650000, 0.150000, 0.700000, 0.150000, 0.750000, 0.150000, 0.800000, 0.150000, 0.850000, 0.150000, 0.900000, 0.150000, 0.950000, 0.150000, 1.000000, 0.150000, 0.000000, 0.200000, 0.050000, 0.200000, 0.100000, 0.200000, 0.150000, 0.200000, 0.200000, 0.200000, 0.250000, 0.200000, 0.300000, 0.200000, 0.350000, 0.200000, 0.400000, 0.200000, 0.450000, 0.200000, 0.500000, 0.200000, 0.550000, 0.200000, 0.600000, 0.200000, 0.650000, 0.200000, 0.700000, 0.200000, 0.750000, 0.200000, 0.800000, 0.200000, 0.850000, 0.200000, 0.900000, 0.200000, 0.950000, 0.200000, 1.000000, 0.200000, 0.000000, 0.250000, 0.050000, 0.250000, 0.100000, 0.250000, 0.150000, 0.250000, 0.200000, 0.250000, 0.250000, 0.250000, 0.300000, 0.250000, 0.350000, 0.250000, 0.400000, 0.250000, 0.450000, 0.250000, 0.500000, 0.250000, 0.550000, 0.250000, 0.600000, 0.250000, 0.650000, 0.250000, 0.700000, 0.250000, 0.750000, 0.250000, 0.800000, 0.250000, 0.850000, 0.250000, 0.900000, 0.250000, 0.950000, 0.250000, 1.000000, 0.250000, 0.000000, 0.300000, 0.050000, 0.300000, 0.100000, 0.300000, 0.150000, 0.300000, 0.200000, 0.300000, 0.250000, 0.300000, 0.300000, 0.300000, 0.350000, 0.300000, 0.400000, 0.300000, 0.450000, 0.300000, 0.500000, 0.300000, 0.550000, 0.300000, 0.600000, 0.300000, 0.650000, 0.300000, 0.700000, 0.300000, 0.750000, 0.300000, 0.800000, 0.300000, 0.850000, 0.300000, 0.900000, 0.300000, 0.950000, 0.300000, 1.000000, 0.300000, 0.000000, 0.350000, 0.050000, 0.350000, 0.100000, 0.350000, 0.150000, 0.350000, 0.200000, 0.350000, 0.250000, 0.350000, 0.300000, 0.350000, 0.350000, 0.350000, 0.400000, 0.350000, 0.450000, 0.350000, 0.500000, 0.350000, 0.550000, 0.350000, 0.600000, 0.350000, 0.650000, 0.350000, 0.700000, 0.350000, 0.750000, 0.350000, 0.800000, 0.350000, 0.850000, 0.350000, 0.900000, 0.350000, 0.950000, 0.350000, 1.000000, 0.350000, 0.000000, 0.400000, 0.050000, 0.400000, 0.100000, 0.400000, 0.150000, 0.400000, 0.200000, 0.400000, 0.250000, 0.400000, 0.300000, 0.400000, 0.350000, 0.400000, 0.400000, 0.400000, 0.450000, 0.400000, 0.500000, 0.400000, 0.550000, 0.400000, 0.600000, 0.400000, 0.650000, 0.400000, 0.700000, 0.400000, 0.750000, 0.400000, 0.800000, 0.400000, 0.850000, 0.400000, 0.900000, 0.400000, 0.950000, 0.400000, 1.000000, 0.400000, 0.000000, 0.450000, 0.050000, 0.450000, 0.100000, 0.450000, 0.150000, 0.450000, 0.200000, 0.450000, 0.250000, 0.450000, 0.300000, 0.450000, 0.350000, 0.450000, 0.400000, 0.450000, 0.450000, 0.450000, 0.500000, 0.450000, 0.550000, 0.450000, 0.600000, 0.450000, 0.650000, 0.450000, 0.700000, 0.450000, 0.750000, 0.450000, 0.800000, 0.450000, 0.850000, 0.450000, 0.900000, 0.450000, 0.950000, 0.450000, 1.000000, 0.450000, 0.000000, 0.500000, 0.050000, 0.500000, 0.100000, 0.500000, 0.150000, 0.500000, 0.200000, 0.500000, 0.250000, 0.500000, 0.300000, 0.500000, 0.350000, 0.500000, 0.400000, 0.500000, 0.450000, 0.500000, 0.500000, 0.500000, 0.550000, 0.500000, 0.600000, 0.500000, 0.650000, 0.500000, 0.700000, 0.500000, 0.750000, 0.500000, 0.800000, 0.500000, 0.850000, 0.500000, 0.900000, 0.500000, 0.950000, 0.500000, 1.000000, 0.500000, 0.000000, 0.550000, 0.050000, 0.550000, 0.100000, 0.550000, 0.150000, 0.550000, 0.200000, 0.550000, 0.250000, 0.550000, 0.300000, 0.550000, 0.350000, 0.550000, 0.400000, 0.550000, 0.450000, 0.550000, 0.500000, 0.550000, 0.550000, 0.550000, 0.600000, 0.550000, 0.650000, 0.550000, 0.700000, 0.550000, 0.750000, 0.550000, 0.800000, 0.550000, 0.850000, 0.550000, 0.900000, 0.550000, 0.950000, 0.550000, 1.000000, 0.550000, 0.000000, 0.600000, 0.050000, 0.600000, 0.100000, 0.600000, 0.150000, 0.600000, 0.200000, 0.600000, 0.250000, 0.600000, 0.300000, 0.600000, 0.350000, 0.600000, 0.400000, 0.600000, 0.450000, 0.600000, 0.500000, 0.600000, 0.550000, 0.600000, 0.600000, 0.600000, 0.650000, 0.600000, 0.700000, 0.600000, 0.750000, 0.600000, 0.800000, 0.600000, 0.850000, 0.600000, 0.900000, 0.600000, 0.950000, 0.600000, 1.000000, 0.600000, 0.000000, 0.650000, 0.050000, 0.650000, 0.100000, 0.650000, 0.150000, 0.650000, 0.200000, 0.650000, 0.250000, 0.650000, 0.300000, 0.650000, 0.350000, 0.650000, 0.400000, 0.650000, 0.450000, 0.650000, 0.500000, 0.650000, 0.550000, 0.650000, 0.600000, 0.650000, 0.650000, 0.650000, 0.700000, 0.650000, 0.750000, 0.650000, 0.800000, 0.650000, 0.850000, 0.650000, 0.900000, 0.650000, 0.950000, 0.650000, 1.000000, 0.650000, 0.000000, 0.700000, 0.050000, 0.700000, 0.100000, 0.700000, 0.150000, 0.700000, 0.200000, 0.700000, 0.250000, 0.700000, 0.300000, 0.700000, 0.350000, 0.700000, 0.400000, 0.700000, 0.450000, 0.700000, 0.500000, 0.700000, 0.550000, 0.700000, 0.600000, 0.700000, 0.650000, 0.700000, 0.700000, 0.700000, 0.750000, 0.700000, 0.800000, 0.700000, 0.850000, 0.700000, 0.900000, 0.700000, 0.950000, 0.700000, 1.000000, 0.700000, 0.000000, 0.750000, 0.050000, 0.750000, 0.100000, 0.750000, 0.150000, 0.750000, 0.200000, 0.750000, 0.250000, 0.750000, 0.300000, 0.750000, 0.350000, 0.750000, 0.400000, 0.750000, 0.450000, 0.750000, 0.500000, 0.750000, 0.550000, 0.750000, 0.600000, 0.750000, 0.650000, 0.750000, 0.700000, 0.750000, 0.750000, 0.750000, 0.800000, 0.750000, 0.850000, 0.750000, 0.900000, 0.750000, 0.950000, 0.750000, 1.000000, 0.750000, 0.000000, 0.800000, 0.050000, 0.800000, 0.100000, 0.800000, 0.150000, 0.800000, 0.200000, 0.800000, 0.250000, 0.800000, 0.300000, 0.800000, 0.350000, 0.800000, 0.400000, 0.800000, 0.450000, 0.800000, 0.500000, 0.800000, 0.550000, 0.800000, 0.600000, 0.800000, 0.650000, 0.800000, 0.700000, 0.800000, 0.750000, 0.800000, 0.800000, 0.800000, 0.850000, 0.800000, 0.900000, 0.800000, 0.950000, 0.800000, 1.000000, 0.800000, 0.000000, 0.850000, 0.050000, 0.850000, 0.100000, 0.850000, 0.150000, 0.850000, 0.200000, 0.850000, 0.250000, 0.850000, 0.300000, 0.850000, 0.350000, 0.850000, 0.400000, 0.850000, 0.450000, 0.850000, 0.500000, 0.850000, 0.550000, 0.850000, 0.600000, 0.850000, 0.650000, 0.850000, 0.700000, 0.850000, 0.750000, 0.850000, 0.800000, 0.850000, 0.850000, 0.850000, 0.900000, 0.850000, 0.950000, 0.850000, 1.000000, 0.850000, 0.000000, 0.900000, 0.050000, 0.900000, 0.100000, 0.900000, 0.150000, 0.900000, 0.200000, 0.900000, 0.250000, 0.900000, 0.300000, 0.900000, 0.350000, 0.900000, 0.400000, 0.900000, 0.450000, 0.900000, 0.500000, 0.900000, 0.550000, 0.900000, 0.600000, 0.900000, 0.650000, 0.900000, 0.700000, 0.900000, 0.750000, 0.900000, 0.800000, 0.900000, 0.850000, 0.900000, 0.900000, 0.900000, 0.950000, 0.900000, 1.000000, 0.900000, 0.000000, 0.950000, 0.050000, 0.950000, 0.100000, 0.950000, 0.150000, 0.950000, 0.200000, 0.950000, 0.250000, 0.950000, 0.300000, 0.950000, 0.350000, 0.950000, 0.400000, 0.950000, 0.450000, 0.950000, 0.500000, 0.950000, 0.550000, 0.950000, 0.600000, 0.950000, 0.650000, 0.950000, 0.700000, 0.950000, 0.750000, 0.950000, 0.800000, 0.950000, 0.850000, 0.950000, 0.900000, 0.950000, 0.950000, 0.950000, 1.000000, 0.950000, 0.025000, 0.000000, 0.075000, 0.000000, 0.125000, 0.000000, 0.175000, 0.000000, 0.225000, 0.000000, 0.275000, 0.000000, 0.325000, 0.000000, 0.375000, 0.000000, 0.425000, 0.000000, 0.475000, 0.000000, 0.525000, 0.000000, 0.575000, 0.000000, 0.625000, 0.000000, 0.675000, 0.000000, 0.725000, 0.000000, 0.775000, 0.000000, 0.825000, 0.000000, 0.875000, 0.000000, 0.925000, 0.000000, 0.975000, 0.000000, 0.025000, 1.000000, 0.075000, 1.000000, 0.125000, 1.000000, 0.175000, 1.000000, 0.225000, 1.000000, 0.275000, 1.000000, 0.325000, 1.000000, 0.375000, 1.000000, 0.425000, 1.000000, 0.475000, 1.000000, 0.525000, 1.000000, 0.575000, 1.000000, 0.625000, 1.000000, 0.675000, 1.000000, 0.725000, 1.000000, 0.775000, 1.000000, 0.825000, 1.000000, 0.875000, 1.000000, 0.925000, 1.000000, 0.975000, 1.000000
    };
    //    顶点法线：
    CGFloat vertexNormals [] = {
        0.190555, -0.979722, -0.061915, 0.162095, -0.979722, -0.117769, 0.269870, -0.942723, -0.196072, 0.317252, -0.942722, -0.103081, 0.117769, -0.979722, -0.162095, 0.196072, -0.942722, -0.269871, 0.061915, -0.979722, -0.190555, 0.103081, -0.942723, -0.317252, -0.000000, -0.979722, -0.200361, -0.000000, -0.942723, -0.333578, -0.061915, -0.979722, -0.190554, -0.103081, -0.942723, -0.317251, -0.117769, -0.979722, -0.162095, -0.196072, -0.942722, -0.269870, -0.162095, -0.979722, -0.117770, -0.269870, -0.942722, -0.196073, -0.190555, -0.979722, -0.061915, -0.317252, -0.942722, -0.103081, -0.200361, -0.979722, 0.000000, -0.333578, -0.942722, 0.000000, -0.190555, -0.979722, 0.061915, -0.317252, -0.942722, 0.103081, -0.162095, -0.979722, 0.117769, -0.269870, -0.942722, 0.196073, -0.117769, -0.979722, 0.162095, -0.196072, -0.942723, 0.269870, -0.061915, -0.979722, 0.190555, -0.103081, -0.942722, 0.317252, 0.000000, -0.979722, 0.200361, 0.000000, -0.942722, 0.333578, 0.061915, -0.979722, 0.190555, 0.103081, -0.942722, 0.317252, 0.117769, -0.979722, 0.162095, 0.196072, -0.942723, 0.269870, 0.162096, -0.979722, 0.117769, 0.269871, -0.942722, 0.196072, 0.190555, -0.979722, 0.061915, 0.317252, -0.942722, 0.103082, 0.200361, -0.979722, 0.000000, 0.333578, -0.942722, 0.000000, 0.380846, -0.882266, -0.276701, 0.447712, -0.882266, -0.145470, 0.276701, -0.882266, -0.380846, 0.145470, -0.882266, -0.447712, -0.000000, -0.882266, -0.470752, -0.145470, -0.882266, -0.447712, -0.276701, -0.882266, -0.380846, -0.380846, -0.882266, -0.276701, -0.447712, -0.882266, -0.145470, -0.470752, -0.882266, 0.000000, -0.447712, -0.882266, 0.145470, -0.380846, -0.882266, 0.276701, -0.276701, -0.882266, 0.380846, -0.145470, -0.882266, 0.447712, 0.000000, -0.882266, 0.470752, 0.145470, -0.882266, 0.447712, 0.276701, -0.882266, 0.380846, 0.380847, -0.882266, 0.276701, 0.447712, -0.882266, 0.145471, 0.470752, -0.882266, 0.000001, 0.485138, -0.800252, -0.352474, 0.570314, -0.800252, -0.185306, 0.352474, -0.800252, -0.485138, 0.185306, -0.800252, -0.570314, -0.000000, -0.800252, -0.599664, -0.185307, -0.800252, -0.570314, -0.352474, -0.800252, -0.485138, -0.485138, -0.800252, -0.352474, -0.570315, -0.800252, -0.185306, -0.599664, -0.800252, -0.000000, -0.570315, -0.800252, 0.185306, -0.485138, -0.800252, 0.352474, -0.352474, -0.800252, 0.485139, -0.185306, -0.800252, 0.570315, -0.000000, -0.800252, 0.599664, 0.185306, -0.800252, 0.570315, 0.352474, -0.800252, 0.485139, 0.485139, -0.800252, 0.352474, 0.570315, -0.800252, 0.185306, 0.599664, -0.800252, 0.000001, 0.578713, -0.698789, -0.420459, 0.680318, -0.698789, -0.221048, 0.420459, -0.698789, -0.578713, 0.221048, -0.698789, -0.680318, -0.000000, -0.698789, -0.715328, -0.221049, -0.698789, -0.680317, -0.420460, -0.698789, -0.578713, -0.578713, -0.698789, -0.420459, -0.680318, -0.698789, -0.221049, -0.715328, -0.698788, 0.000000, -0.680318, -0.698788, 0.221049, -0.578713, -0.698788, 0.420460, -0.420459, -0.698788, 0.578713, -0.221049, -0.698788, 0.680318, -0.000000, -0.698788, 0.715328, 0.221049, -0.698789, 0.680318, 0.420460, -0.698788, 0.578713, 0.578713, -0.698788, 0.420460, 0.680318, -0.698788, 0.221049, 0.715328, -0.698788, 0.000001, 0.658807, -0.580401, -0.478652, 0.774475, -0.580401, -0.251641, 0.478652, -0.580401, -0.658808, 0.251642, -0.580401, -0.774475, -0.000000, -0.580401, -0.814331, -0.251642, -0.580401, -0.774475, -0.478652, -0.580401, -0.658808, -0.658808, -0.580401, -0.478652, -0.774475, -0.580401, -0.251642, -0.814331, -0.580401, 0.000000, -0.774475, -0.580401, 0.251642, -0.658808, -0.580401, 0.478652, -0.478652, -0.580401, 0.658808, -0.251642, -0.580401, 0.774475, 0.000000, -0.580401, 0.814331, 0.251642, -0.580401, 0.774475, 0.478652, -0.580401, 0.658808, 0.658808, -0.580401, 0.478652, 0.774475, -0.580401, 0.251642, 0.814331, -0.580401, 0.000001, 0.723291, -0.447994, -0.525502, 0.850280, -0.447994, -0.276272, 0.525501, -0.447994, -0.723291, 0.276272, -0.447994, -0.850279, -0.000000, -0.447994, -0.894037, -0.276273, -0.447994, -0.850279, -0.525502, -0.447994, -0.723291, -0.723291, -0.447994, -0.525502, -0.850279, -0.447994, -0.276272, -0.894037, -0.447994, 0.000000, -0.850279, -0.447994, 0.276273, -0.723291, -0.447994, 0.525502, -0.525502, -0.447994, 0.723291, -0.276273, -0.447994, 0.850279, 0.000000, -0.447994, 0.894037, 0.276273, -0.447994, 0.850280, 0.525502, -0.447994, 0.723291, 0.723291, -0.447994, 0.525502, 0.850279, -0.447994, 0.276272, 0.894037, -0.447994, 0.000001, 0.770524, -0.304789, -0.559819, 0.905806, -0.304789, -0.294313, 0.559818, -0.304789, -0.770524, 0.294314, -0.304789, -0.905805, -0.000000, -0.304789, -0.952420, -0.294314, -0.304789, -0.905805, -0.559819, -0.304789, -0.770524, -0.770524, -0.304789, -0.559818, -0.905805, -0.304789, -0.294314, -0.952420, -0.304789, 0.000000, -0.905805, -0.304789, 0.294314, -0.770524, -0.304789, 0.559819, -0.559818, -0.304789, 0.770524, -0.294314, -0.304789, 0.905805, 0.000000, -0.304789, 0.952420, 0.294314, -0.304789, 0.905805, 0.559818, -0.304789, 0.770524, 0.770524, -0.304789, 0.559818, 0.905805, -0.304788, 0.294314, 0.952420, -0.304788, 0.000001, 0.799335, -0.154249, -0.580751, 0.939675, -0.154249, -0.305318, 0.580751, -0.154249, -0.799335, 0.305319, -0.154249, -0.939674, 0.000000, -0.154249, -0.988032, -0.305319, -0.154249, -0.939674, -0.580751, -0.154249, -0.799335, -0.799335, -0.154249, -0.580751, -0.939674, -0.154249, -0.305319, -0.988032, -0.154249, 0.000000, -0.939674, -0.154249, 0.305319, -0.799335, -0.154248, 0.580751, -0.580751, -0.154249, 0.799335, -0.305319, -0.154249, 0.939674, 0.000000, -0.154249, 0.988032, 0.305319, -0.154248, 0.939674, 0.580751, -0.154248, 0.799335, 0.799335, -0.154248, 0.580751, 0.939674, -0.154249, 0.305319, 0.988032, -0.154249, 0.000001, 0.809017, 0.000000, -0.587785, 0.951057, 0.000000, -0.309016, 0.587785, 0.000000, -0.809017, 0.309017, 0.000000, -0.951057, 0.000000, -0.000000, -1.000000, -0.309017, -0.000000, -0.951056, -0.587786, 0.000000, -0.809017, -0.809017, 0.000000, -0.587785, -0.951057, 0.000000, -0.309017, -1.000000, 0.000000, 0.000000, -0.951057, 0.000000, 0.309017, -0.809017, 0.000000, 0.587785, -0.587785, 0.000000, 0.809017, -0.309017, 0.000000, 0.951057, 0.000000, -0.000000, 1.000000, 0.309017, -0.000000, 0.951057, 0.587785, -0.000000, 0.809017, 0.809017, 0.000000, 0.587785, 0.951057, 0.000000, 0.309017, 1.000000, 0.000000, 0.000001, 0.799335, 0.154249, -0.580751, 0.939675, 0.154249, -0.305318, 0.580751, 0.154249, -0.799335, 0.305319, 0.154249, -0.939674, 0.000000, 0.154249, -0.988032, -0.305319, 0.154249, -0.939674, -0.580751, 0.154249, -0.799335, -0.799335, 0.154249, -0.580750, -0.939674, 0.154249, -0.305319, -0.988032, 0.154249, 0.000000, -0.939674, 0.154249, 0.305319, -0.799335, 0.154248, 0.580751, -0.580751, 0.154249, 0.799335, -0.305319, 0.154249, 0.939674, 0.000000, 0.154249, 0.988032, 0.305319, 0.154249, 0.939674, 0.580751, 0.154248, 0.799335, 0.799335, 0.154248, 0.580751, 0.939674, 0.154249, 0.305319, 0.988032, 0.154249, 0.000001, 0.770524, 0.304789, -0.559819, 0.905806, 0.304789, -0.294313, 0.559818, 0.304789, -0.770524, 0.294314, 0.304789, -0.905805, -0.000000, 0.304789, -0.952420, -0.294314, 0.304789, -0.905805, -0.559819, 0.304789, -0.770524, -0.770524, 0.304789, -0.559818, -0.905805, 0.304789, -0.294314, -0.952420, 0.304789, 0.000000, -0.905805, 0.304789, 0.294314, -0.770524, 0.304789, 0.559819, -0.559818, 0.304789, 0.770524, -0.294314, 0.304789, 0.905805, 0.000000, 0.304789, 0.952420, 0.294314, 0.304789, 0.905805, 0.559819, 0.304789, 0.770524, 0.770524, 0.304789, 0.559818, 0.905805, 0.304788, 0.294314, 0.952420, 0.304788, 0.000001, 0.723291, 0.447994, -0.525501, 0.850280, 0.447994, -0.276272, 0.525501, 0.447994, -0.723291, 0.276272, 0.447994, -0.850279, -0.000000, 0.447994, -0.894037, -0.276273, 0.447994, -0.850279, -0.525502, 0.447994, -0.723291, -0.723291, 0.447994, -0.525501, -0.850279, 0.447994, -0.276272, -0.894037, 0.447994, -0.000000, -0.850279, 0.447994, 0.276273, -0.723291, 0.447994, 0.525502, -0.525501, 0.447994, 0.723291, -0.276273, 0.447994, 0.850280, 0.000000, 0.447994, 0.894037, 0.276273, 0.447994, 0.850280, 0.525502, 0.447994, 0.723291, 0.723291, 0.447994, 0.525502, 0.850279, 0.447994, 0.276272, 0.894037, 0.447994, 0.000001, 0.658808, 0.580401, -0.478652, 0.774475, 0.580401, -0.251641, 0.478652, 0.580401, -0.658808, 0.251642, 0.580401, -0.774475, -0.000000, 0.580401, -0.814331, -0.251642, 0.580401, -0.774475, -0.478652, 0.580401, -0.658807, -0.658808, 0.580401, -0.478652, -0.774475, 0.580401, -0.251642, -0.814331, 0.580401, -0.000000, -0.774475, 0.580401, 0.251642, -0.658808, 0.580401, 0.478652, -0.478652, 0.580401, 0.658808, -0.251642, 0.580401, 0.774475, 0.000000, 0.580401, 0.814331, 0.251642, 0.580401, 0.774475, 0.478652, 0.580401, 0.658808, 0.658808, 0.580401, 0.478652, 0.774475, 0.580401, 0.251642, 0.814331, 0.580401, 0.000001, 0.578713, 0.698789, -0.420459, 0.680318, 0.698789, -0.221048, 0.420459, 0.698789, -0.578713, 0.221048, 0.698789, -0.680318, -0.000000, 0.698789, -0.715328, -0.221049, 0.698789, -0.680318, -0.420460, 0.698789, -0.578713, -0.578713, 0.698789, -0.420459, -0.680318, 0.698788, -0.221049, -0.715328, 0.698788, -0.000000, -0.680318, 0.698788, 0.221049, -0.578713, 0.698788, 0.420460, -0.420459, 0.698788, 0.578713, -0.221049, 0.698788, 0.680318, -0.000000, 0.698788, 0.715328, 0.221049, 0.698788, 0.680318, 0.420460, 0.698788, 0.578713, 0.578713, 0.698788, 0.420459, 0.680318, 0.698788, 0.221049, 0.715329, 0.698788, 0.000001, 0.485138, 0.800252, -0.352474, 0.570315, 0.800252, -0.185306, 0.352473, 0.800252, -0.485138, 0.185306, 0.800252, -0.570314, -0.000000, 0.800252, -0.599664, -0.185307, 0.800252, -0.570314, -0.352474, 0.800252, -0.485138, -0.485138, 0.800252, -0.352474, -0.570315, 0.800252, -0.185306, -0.599664, 0.800252, -0.000000, -0.570315, 0.800252, 0.185306, -0.485138, 0.800252, 0.352474, -0.352474, 0.800252, 0.485139, -0.185306, 0.800252, 0.570315, -0.000000, 0.800252, 0.599664, 0.185306, 0.800252, 0.570314, 0.352474, 0.800252, 0.485139, 0.485139, 0.800252, 0.352474, 0.570315, 0.800252, 0.185306, 0.599664, 0.800252, 0.000001, 0.380846, 0.882266, -0.276701, 0.447712, 0.882266, -0.145470, 0.276701, 0.882266, -0.380846, 0.145470, 0.882266, -0.447712, -0.000000, 0.882266, -0.470752, -0.145470, 0.882266, -0.447712, -0.276701, 0.882266, -0.380846, -0.380846, 0.882266, -0.276701, -0.447712, 0.882266, -0.145470, -0.470752, 0.882266, -0.000000, -0.447712, 0.882266, 0.145470, -0.380846, 0.882266, 0.276701, -0.276701, 0.882266, 0.380846, -0.145470, 0.882266, 0.447712, 0.000000, 0.882266, 0.470752, 0.145470, 0.882266, 0.447712, 0.276701, 0.882266, 0.380846, 0.380847, 0.882266, 0.276701, 0.447712, 0.882266, 0.145471, 0.470752, 0.882266, 0.000001, 0.269870, 0.942723, -0.196072, 0.317252, 0.942722, -0.103081, 0.196072, 0.942722, -0.269871, 0.103081, 0.942723, -0.317252, -0.000000, 0.942723, -0.333578, -0.103081, 0.942723, -0.317251, -0.196072, 0.942722, -0.269870, -0.269870, 0.942722, -0.196072, -0.317252, 0.942722, -0.103081, -0.333578, 0.942722, -0.000000, -0.317252, 0.942722, 0.103081, -0.269870, 0.942722, 0.196073, -0.196072, 0.942722, 0.269870, -0.103081, 0.942722, 0.317252, 0.000000, 0.942722, 0.333578, 0.103081, 0.942722, 0.317252, 0.196072, 0.942723, 0.269870, 0.269871, 0.942723, 0.196072, 0.317252, 0.942722, 0.103082, 0.333578, 0.942722, 0.000000, 0.162095, 0.979722, -0.117769, 0.190555, 0.979722, -0.061915, 0.117769, 0.979722, -0.162095, 0.061915, 0.979722, -0.190555, -0.000000, 0.979722, -0.200361, -0.061915, 0.979722, -0.190554, -0.117769, 0.979722, -0.162095, -0.162095, 0.979722, -0.117770, -0.190555, 0.979722, -0.061915, -0.200361, 0.979722, 0.000000, -0.190555, 0.979722, 0.061915, -0.162095, 0.979722, 0.117769, -0.117769, 0.979722, 0.162096, -0.061915, 0.979722, 0.190555, 0.000000, 0.979722, 0.200361, 0.061915, 0.979722, 0.190555, 0.117769, 0.979722, 0.162095, 0.162096, 0.979722, 0.117769, 0.190555, 0.979722, 0.061915, 0.200361, 0.979722, 0.000000, -0.000000, -1.000000, -0.000000, -0.000000, 1.000000, 0.000000
    };
    //    面（指数从0开始）
    GLushort faces[] = {
        0, 1, 21, 20, 1, 2, 22, 21, 2, 3, 23, 22, 3, 4, 24, 23, 4, 5, 25, 24, 5, 6, 26, 25, 6, 7, 27, 26, 7, 8, 28, 27, 8, 9, 29, 28, 9, 10, 30, 29, 10, 11, 31, 30, 11, 12, 32, 31, 12, 13, 33, 32, 13, 14, 34, 33, 14, 15, 35, 34, 15, 16, 36, 35, 16, 17, 37, 36, 17, 18, 38, 37, 18, 19, 39, 38, 19, 0, 20, 39, 20, 21, 41, 40, 21, 22, 42, 41, 22, 23, 43, 42, 23, 24, 44, 43, 24, 25, 45, 44, 25, 26, 46, 45, 26, 27, 47, 46, 27, 28, 48, 47, 28, 29, 49, 48, 29, 30, 50, 49, 30, 31, 51, 50, 31, 32, 52, 51, 32, 33, 53, 52, 33, 34, 54, 53, 34, 35, 55, 54, 35, 36, 56, 55, 36, 37, 57, 56, 37, 38, 58, 57, 38, 39, 59, 58, 39, 20, 40, 59, 40, 41, 61, 60, 41, 42, 62, 61, 42, 43, 63, 62, 43, 44, 64, 63, 44, 45, 65, 64, 45, 46, 66, 65, 46, 47, 67, 66, 47, 48, 68, 67, 48, 49, 69, 68, 49, 50, 70, 69, 50, 51, 71, 70, 51, 52, 72, 71, 52, 53, 73, 72, 53, 54, 74, 73, 54, 55, 75, 74, 55, 56, 76, 75, 56, 57, 77, 76, 57, 58, 78, 77, 58, 59, 79, 78, 59, 40, 60, 79, 60, 61, 81, 80, 61, 62, 82, 81, 62, 63, 83, 82, 63, 64, 84, 83, 64, 65, 85, 84, 65, 66, 86, 85, 66, 67, 87, 86, 67, 68, 88, 87, 68, 69, 89, 88, 69, 70, 90, 89, 70, 71, 91, 90, 71, 72, 92, 91, 72, 73, 93, 92, 73, 74, 94, 93, 74, 75, 95, 94, 75, 76, 96, 95, 76, 77, 97, 96, 77, 78, 98, 97, 78, 79, 99, 98, 79, 60, 80, 99, 80, 81, 101, 100, 81, 82, 102, 101, 82, 83, 103, 102, 83, 84, 104, 103, 84, 85, 105, 104, 85, 86, 106, 105, 86, 87, 107, 106, 87, 88, 108, 107, 88, 89, 109, 108, 89, 90, 110, 109, 90, 91, 111, 110, 91, 92, 112, 111, 92, 93, 113, 112, 93, 94, 114, 113, 94, 95, 115, 114, 95, 96, 116, 115, 96, 97, 117, 116, 97, 98, 118, 117, 98, 99, 119, 118, 99, 80, 100, 119, 100, 101, 121, 120, 101, 102, 122, 121, 102, 103, 123, 122, 103, 104, 124, 123, 104, 105, 125, 124, 105, 106, 126, 125, 106, 107, 127, 126, 107, 108, 128, 127, 108, 109, 129, 128, 109, 110, 130, 129, 110, 111, 131, 130, 111, 112, 132, 131, 112, 113, 133, 132, 113, 114, 134, 133, 114, 115, 135, 134, 115, 116, 136, 135, 116, 117, 137, 136, 117, 118, 138, 137, 118, 119, 139, 138, 119, 100, 120, 139, 120, 121, 141, 140, 121, 122, 142, 141, 122, 123, 143, 142, 123, 124, 144, 143, 124, 125, 145, 144, 125, 126, 146, 145, 126, 127, 147, 146, 127, 128, 148, 147, 128, 129, 149, 148, 129, 130, 150, 149, 130, 131, 151, 150, 131, 132, 152, 151, 132, 133, 153, 152, 133, 134, 154, 153, 134, 135, 155, 154, 135, 136, 156, 155, 136, 137, 157, 156, 137, 138, 158, 157, 138, 139, 159, 158, 139, 120, 140, 159, 140, 141, 161, 160, 141, 142, 162, 161, 142, 143, 163, 162, 143, 144, 164, 163, 144, 145, 165, 164, 145, 146, 166, 165, 146, 147, 167, 166, 147, 148, 168, 167, 148, 149, 169, 168, 149, 150, 170, 169, 150, 151, 171, 170, 151, 152, 172, 171, 152, 153, 173, 172, 153, 154, 174, 173, 154, 155, 175, 174, 155, 156, 176, 175, 156, 157, 177, 176, 157, 158, 178, 177, 158, 159, 179, 178, 159, 140, 160, 179, 160, 161, 181, 180, 161, 162, 182, 181, 162, 163, 183, 182, 163, 164, 184, 183, 164, 165, 185, 184, 165, 166, 186, 185, 166, 167, 187, 186, 167, 168, 188, 187, 168, 169, 189, 188, 169, 170, 190, 189, 170, 171, 191, 190, 171, 172, 192, 191, 172, 173, 193, 192, 173, 174, 194, 193, 174, 175, 195, 194, 175, 176, 196, 195, 176, 177, 197, 196, 177, 178, 198, 197, 178, 179, 199, 198, 179, 160, 180, 199, 180, 181, 201, 200, 181, 182, 202, 201, 182, 183, 203, 202, 183, 184, 204, 203, 184, 185, 205, 204, 185, 186, 206, 205, 186, 187, 207, 206, 187, 188, 208, 207, 188, 189, 209, 208, 189, 190, 210, 209, 190, 191, 211, 210, 191, 192, 212, 211, 192, 193, 213, 212, 193, 194, 214, 213, 194, 195, 215, 214, 195, 196, 216, 215, 196, 197, 217, 216, 197, 198, 218, 217, 198, 199, 219, 218, 199, 180, 200, 219, 200, 201, 221, 220, 201, 202, 222, 221, 202, 203, 223, 222, 203, 204, 224, 223, 204, 205, 225, 224, 205, 206, 226, 225, 206, 207, 227, 226, 207, 208, 228, 227, 208, 209, 229, 228, 209, 210, 230, 229, 210, 211, 231, 230, 211, 212, 232, 231, 212, 213, 233, 232, 213, 214, 234, 233, 214, 215, 235, 234, 215, 216, 236, 235, 216, 217, 237, 236, 217, 218, 238, 237, 218, 219, 239, 238, 219, 200, 220, 239, 220, 221, 241, 240, 221, 222, 242, 241, 222, 223, 243, 242, 223, 224, 244, 243, 224, 225, 245, 244, 225, 226, 246, 245, 226, 227, 247, 246, 227, 228, 248, 247, 228, 229, 249, 248, 229, 230, 250, 249, 230, 231, 251, 250, 231, 232, 252, 251, 232, 233, 253, 252, 233, 234, 254, 253, 234, 235, 255, 254, 235, 236, 256, 255, 236, 237, 257, 256, 237, 238, 258, 257, 238, 239, 259, 258, 239, 220, 240, 259, 240, 241, 261, 260, 241, 242, 262, 261, 242, 243, 263, 262, 243, 244, 264, 263, 244, 245, 265, 264, 245, 246, 266, 265, 246, 247, 267, 266, 247, 248, 268, 267, 248, 249, 269, 268, 249, 250, 270, 269, 250, 251, 271, 270, 251, 252, 272, 271, 252, 253, 273, 272, 253, 254, 274, 273, 254, 255, 275, 274, 255, 256, 276, 275, 256, 257, 277, 276, 257, 258, 278, 277, 258, 259, 279, 278, 259, 240, 260, 279, 260, 261, 281, 280, 261, 262, 282, 281, 262, 263, 283, 282, 263, 264, 284, 283, 264, 265, 285, 284, 265, 266, 286, 285, 266, 267, 287, 286, 267, 268, 288, 287, 268, 269, 289, 288, 269, 270, 290, 289, 270, 271, 291, 290, 271, 272, 292, 291, 272, 273, 293, 292, 273, 274, 294, 293, 274, 275, 295, 294, 275, 276, 296, 295, 276, 277, 297, 296, 277, 278, 298, 297, 278, 279, 299, 298, 279, 260, 280, 299, 280, 281, 301, 300, 281, 282, 302, 301, 282, 283, 303, 302, 283, 284, 304, 303, 284, 285, 305, 304, 285, 286, 306, 305, 286, 287, 307, 306, 287, 288, 308, 307, 288, 289, 309, 308, 289, 290, 310, 309, 290, 291, 311, 310, 291, 292, 312, 311, 292, 293, 313, 312, 293, 294, 314, 313, 294, 295, 315, 314, 295, 296, 316, 315, 296, 297, 317, 316, 297, 298, 318, 317, 298, 299, 319, 318, 299, 280, 300, 319, 300, 301, 321, 320, 301, 302, 322, 321, 302, 303, 323, 322, 303, 304, 324, 323, 304, 305, 325, 324, 305, 306, 326, 325, 306, 307, 327, 326, 307, 308, 328, 327, 308, 309, 329, 328, 309, 310, 330, 329, 310, 311, 331, 330, 311, 312, 332, 331, 312, 313, 333, 332, 313, 314, 334, 333, 314, 315, 335, 334, 315, 316, 336, 335, 316, 317, 337, 336, 317, 318, 338, 337, 318, 319, 339, 338, 319, 300, 320, 339, 320, 321, 341, 340, 321, 322, 342, 341, 322, 323, 343, 342, 323, 324, 344, 343, 324, 325, 345, 344, 325, 326, 346, 345, 326, 327, 347, 346, 327, 328, 348, 347, 328, 329, 349, 348, 329, 330, 350, 349, 330, 331, 351, 350, 331, 332, 352, 351, 332, 333, 353, 352, 333, 334, 354, 353, 334, 335, 355, 354, 335, 336, 356, 355, 336, 337, 357, 356, 337, 338, 358, 357, 338, 339, 359, 358, 339, 320, 340, 359, 340, 341, 361, 360, 341, 342, 362, 361, 342, 343, 363, 362, 343, 344, 364, 363, 344, 345, 365, 364, 345, 346, 366, 365, 346, 347, 367, 366, 347, 348, 368, 367, 348, 349, 369, 368, 349, 350, 370, 369, 350, 351, 371, 370, 351, 352, 372, 371, 352, 353, 373, 372, 353, 354, 374, 373, 354, 355, 375, 374, 355, 356, 376, 375, 356, 357, 377, 376, 357, 358, 378, 377, 358, 359, 379, 378, 359, 340, 360, 379, 1, 0, 380, 2, 1, 380, 3, 2, 380, 4, 3, 380, 5, 4, 380, 6, 5, 380, 7, 6, 380, 8, 7, 380, 9, 8, 380, 10, 9, 380, 11, 10, 380, 12, 11, 380, 13, 12, 380, 14, 13, 380, 15, 14, 380, 16, 15, 380, 17, 16, 380, 18, 17, 380, 19, 18, 380, 0, 19, 380, 360, 361, 381, 361, 362, 381, 362, 363, 381, 363, 364, 381, 364, 365, 381, 365, 366, 381, 366, 367, 381, 367, 368, 381, 368, 369, 381, 369, 370, 381, 370, 371, 381, 371, 372, 381, 372, 373, 381, 373, 374, 381, 374, 375, 381, 375, 376, 381, 376, 377, 381, 377, 378, 381, 378, 379, 381, 379, 360, 381
    };
    
    Tex *tex = [[GameManager getInstance] getTex: @"snip20160421.png" isImage: YES];
    GLuint textureID = [tex getTextureID];
    
    int verticesLength = sizeof(vertices) / sizeof(GLfloat);
    int facesLength = sizeof(faces) / sizeof(GLushort);
    
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnable(GL_NORMALIZE);
    
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    
    glEnable(GL_TEXTURE_2D);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glBindTexture(GL_TEXTURE_2D, textureID);
    glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates);
    glNormalPointer(GL_FLOAT, 0, vertexNormals);
    
    glColor4f(1, 1, 1, 1);
    
    //Matrix-Operations
    glPushMatrix();
    glTranslatef(0, 0, -30);
    static int angle = 0; angle += 2;
    glRotatef(angle, 1, 1, 1);
    glDrawElements(GL_TRIANGLES, facesLength, GL_UNSIGNED_SHORT, faces);
//    glDrawArrays(GL_TRIANGLE_STRIP, 0, verticesLength/3);
    glPopMatrix();
    
    //Cleanup
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_CULL_FACE);
}

- (void)drawMyCube{
    CGFloat Vertices[]= {
        //qian
        -4, -4, 4,
        4, -4, 4,
        4, 4, 4,
        -4, 4, 4,
        //shang
        -4, 4, 4,
        4, 4, 4,
        4, 4, -4,
        -4, 4, -4,
        //hou
        -4, 4, -4,
        4, 4, -4,
        4, -4, -4,
        -4, -4, -4,
        //di
        -4, -4, -4,
        4, -4, -4,
        4, -4, 4,
        -4, -4, 4,
        //you
        4, -4, 4,
        4, -4, -4,
        4, 4, -4,
        4, 4, 4,
        //zuo
        -4, -4, -4,
        -4, -4, 4,
        -4, 4, 4,
        -4, 4, -4
    };
    CGFloat VertexNormals[] = {
        0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0
    };
    CGFloat TextureCoordinates[]={
        0.375, 0, 0.625, 0, 0.625, 0.25, 0.375, 0.25, 0.375, 0.25, 0.625, 0.25, 0.625, 0.5, 0.375, 0.5, 0.375, 0.5, 0.625, 0.5, 0.625, 0.75, 0.375, 0.75, 0.375, 0.75, 0.625, 0.75, 0.625, 1, 0.375, 1, 0.625, 0, 0.875, 0, 0.875, 0.25, 0.625, 0.25, 0.125, 0, 0.375, 0, 0.375, 0.25, 0.125, 0.25
    };
    GLushort Faces[] = {
        0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23
    };
    Tex *tex = [[GameManager getInstance] getTex: @"snip20160421.png" isImage: YES];
    GLuint textureID = [tex getTextureID];
    int verticesLength = sizeof(Vertices) / sizeof(GLfloat);
    int faceLength = sizeof(Faces) / sizeof(GLushort);
    
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnable(GL_NORMALIZE);
    
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    
    glEnable(GL_TEXTURE_2D);
    glVertexPointer(3, GL_FLOAT, 0, Vertices);
    glBindTexture(GL_TEXTURE_2D, textureID);
    glTexCoordPointer(2, GL_FLOAT, 0, TextureCoordinates);
    glNormalPointer(GL_FLOAT, 0, VertexNormals);
    
    glColor4f(1, 1, 1, 1);
    
    //Matrix-Operations
    glPushMatrix();
    glTranslatef(0, 0, -30);
    static int angle = 0; angle += 2;
    glRotatef(angle, 1, 0.5, 0);
//    glDrawArrays(GL_TRIANGLE_STRIP, 0, verticesLength/3);
    glDrawElements(GL_TRIANGLES, faceLength, GL_UNSIGNED_SHORT, Faces);
    glPopMatrix();
    
    //Cleanup
//    glDisableClientState(GL_NORMAL_ARRAY);
    glDisable(GL_NORMALIZE);
    glDisable(GL_CULL_FACE);
}

- (Tex *) getTex: (NSString*) name isImage: (bool) imgFlag { 
	Tex *tex = [[self getDictionary] objectForKey: name];
	if (!tex) {
		tex = [[Tex alloc] init];
        if (imgFlag) {            
            [tex createTexFromImage: name];             
        } else {
            [tex createTexFromString: name];
        }    
        [[self getDictionary] setObject: tex forKey: name];
        [tex release];         
	}          
	return tex;  
}

#pragma mark ============================= Helper Methods ===============================

- (NSMutableDictionary *) getDictionary {
	if (!dictionary) { 
		dictionary = [[NSMutableDictionary alloc] init]; 
	}
	return dictionary;
}

- (void) removeFromDictionary: (NSString*) name {
    [[self getDictionary] removeObjectForKey: name];
} 

- (int) getRndBetween: (int) bottom and: (int) top {		
	int rnd = bottom + (arc4random() % (top+1-bottom)); 
	return rnd;
} 

- (void) dealloc { 
    [dictionary release];
    [super dealloc];
}

@end
